<template>
    <el-dialog :title="dialogStatus | titleFilter" :close-on-click-modal="false" width="600px" :visible.sync="visible">
        <el-form ref="temp" :model="temp" :rules="rule" label-width="120px" @keyup.enter.native="dataFormSubmit()">

            <el-form-item label="结算方式" prop="itemsName">
                <el-input v-model="temp.settlementName" placeholder="请输入" />
            </el-form-item>

            <el-form-item label="是否启用">
                <el-radio-group v-model="temp.enableFlag">
                    <el-radio v-for="(item,index) in enableFlagType" :label="index">{{item}}
                    </el-radio>
                    <!-- <el-radio label="公司" value="2"></el-radio> -->
                </el-radio-group>
            </el-form-item>

        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="visible = false">
                取消
            </el-button>
            <el-button type="primary" @click="dataFormSubmit">
                确认
            </el-button>
        </span>
    </el-dialog>
</template>
<script>
import { createFinancesettlement, upDataFinancesettlement } from '@/api/charge'// 请求数据
import { enableFlagType, projectState, billingCycleFlagType, moneyAccurateType, billingCycleType, chargeCriterionType, countMethodType } from '@/utils/enum' //字典
export default {
    filters: {
        // 过滤弹框的标题
        titleFilter (type) {
            const textMap = {
                create: '新增',
                update: '修改'
            }
            return textMap[type]
        }
    },
    computed: {
        // projectState_ () {
        //     // let arr = [{ lable: '全部', value: '' }]
        //     let arr = []
        //     for (let key in projectState) {
        //         arr.push({
        //             lable: projectState[key],
        //             value: key
        //         })
        //     }
        //     return arr
        // },
    },
    data () {
        return {
            visible: false,
            dialogStatus: '', // 弹框新增或者修改
            temp: { // 表单数据
                id: '',
                settlementName: "",//结算方式
                enableFlag: '1',//是否启用
            },
            rule: {
                settlementName: [
                    { required: true, message: '不能为空', trigger: 'blur' }
                ],
                enableFlag: [
                    { required: true, message: '不能为空', trigger: 'blur' }
                ]
            },
            enableFlagType,//结算方式
        }
    },
    created () {
    },
    methods: {
        // 初始化
        init (status, param) {
            this.dialogStatus = status // 标题
            this.visible = true // 显示
            this[status](param) // 新增或者修改
            this.$nextTick(() => { // 重置表单
                this.$refs['temp'].clearValidate()
            })
        },
        create () {
            this.resetTemp() // 清空表单
        },

        async update (param) {
            // console.log("--->>>>>", param)
            let data = Object.assign({}, param)//从上一页带过来当前的数据
            // const { data, code } = await getParkDetails({}, param.id) // 从后台获取当前的的数据
            // 成功
            this.temp.id = data.id
            this.temp.settlementName = data.settlementName
            this.temp.enableFlag = data.enableFlag.toString()


        },
        // 新增数据清空表单数据
        resetTemp () {
            this.temp = {
                id: '',
                settlementName: "",//结算方式
                enableFlag: '1',//是否启用
            }
        },
        //获取园区list
        // async getPark () {
        //     const res = await getParkListAll().catch(e => { })
        //     // 失败
        //     if (!res) { this.listLoading = false; return }
        //     // 成功
        //     const { data, code, message } = res
        //     this.park_options = data
        //     // console.log("园区list", data)
        // },

        // 表单提交
        dataFormSubmit () {
            this.$refs['temp'].validate(async (valid) => {
                if (!valid) return
                const params = {
                    'id': this.temp.id || undefined,
                    'settlementName': this.temp.settlementName,
                    'enableFlag': this.temp.enableFlag,
                }
                const textMap = {
                    create: createFinancesettlement, // 新增
                    update: upDataFinancesettlement // 修改
                }

                // 提交表单
                const { code, message } = await textMap[this.dialogStatus](params)

                // 成功
                this.$message({
                    message: '操作成功',
                    type: 'success',
                    duration: 1500,
                    onClose: () => {
                        this.visible = false
                        this.$emit('getList')
                    }
                })
            })
        },

        // ===>>>>>>>>>
        // 选择园区
        park_change (e) {
            // console.log(e)
            this.getCharge()
        },
    }
}
</script>

<style lang="scss">
.mod-menu {
    .menu-list__input,
    .icon-list__input {
        > .el-input__inner {
            cursor: pointer;
        }
    }
    &__icon-popover {
        width: 458px;
        overflow: hidden;
    }
    &__icon-inner {
        width: 478px;
        max-height: 258px;
        overflow-x: hidden;
        overflow-y: auto;
    }
    &__icon-list {
        width: 458px;
        padding: 0;
        margin: -8px 0 0 -8px;
        > .el-button {
            padding: 8px;
            margin: 8px 0 0 8px;
            > span {
                display: inline-block;
                vertical-align: middle;
                width: 18px;
                height: 18px;
                font-size: 18px;
            }
        }
    }
    .icon-list__tips {
        font-size: 18px;
        text-align: center;
        color: #e6a23c;
        cursor: pointer;
    }
}
</style>
